#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    bool validPartition(vector<int> &nums)
    {
        if (nums.size() == 2)
            return nums[0] == nums[1];
        vector<bool> dp(nums.size() + 1, false);
        dp[0] = true;
        dp[1] = false;
        dp[2] = nums[0] == nums[1];
        for (int i = 2; i < nums.size(); i++)
        {
            if (nums[i - 1] == nums[i])
            {
                dp[i + 1] = dp[i - 1];
                if (nums[i - 2] == nums[i - 1])
                    dp[i + 1] = dp[i + 1] || dp[i - 2];
            }
            else if (nums[i - 2] + 1 == nums[i - 1] && nums[i - 1] + 1 == nums[i])
                dp[i + 1] = dp[i - 2];
        }
        return dp[nums.size()];
    }
};

int main()
{
    cout << "Code2369" << endl;
    Solution s;
    vector<int> nums = {
        1,
        1,
        1,
        1,
        1,
        1,
        1,
    };
    cout << s.validPartition(nums) << endl;
    return 0;
}